package felix.rule.data.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.JsonNode;
import felix.rule.data.plugin.ComponentDescriptor;
import felix.rule.data.plugin.ComponentType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

@EqualsAndHashCode(callSuper = true)
@TableName("component_descriptor")
@Data
@NoArgsConstructor
public class ComponentDescriptorEntity extends BaseEntity<ComponentDescriptor> {

    private ComponentType type;

    private String name;

    private String clazz;

    private JsonNode configurationDescriptor;

    public ComponentDescriptorEntity(ComponentDescriptor componentDescriptor) {
        BeanUtils.copyProperties(componentDescriptor, this);
    }

    @Override
    public ComponentDescriptor toData() {
        ComponentDescriptor componentDescriptor = new ComponentDescriptor();
        BeanUtils.copyProperties(this, componentDescriptor);
        return componentDescriptor;
    }
}
